package eom.example.elasticsearch.config;

import io.searchbox.client.JestClientFactory;
import io.searchbox.client.config.HttpClientConfig;
import io.searchbox.client.http.JestHttpClient;
import org.apache.http.HttpHost;
import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.RestHighLevelClient;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;



/**
 * @author X.I.O
 * @title: ElasticSearchClientConfig
 * @projectName springboot
 * @description: TODO
 * @date 2021/11/2 1:16
 */
@Configuration
public class ElasticSearchClientConfig {

    @Bean
    public RestHighLevelClient restHighLevelClient(){
        RestHighLevelClient client = new RestHighLevelClient(
                RestClient.builder(
                        new HttpHost("192.168.80.128", 9200, "http")
                )
        );
        return client;
    }

    @Bean
    public JestHttpClient getEsClient(){
        JestClientFactory factory = new JestClientFactory();
        factory.setHttpClientConfig(new HttpClientConfig.Builder(
                "http://192.168.80.128:9200")
                .multiThreaded(true)
                .readTimeout(5000)
                .build());

        return (JestHttpClient) factory.getObject();
    }


}
